/**
 * 后台管理系统相关菜单
 */

var express = require("express");
var router = express.Router();

/* GET home page. */
router.get("/", function (req, res, next) {
  res.status(200).json({ code: 1, message: "success", result: "index" });
});
router.get("/test", function (req, res, next) {
  res.status(200).json({ code: 1, message: "success", result: "test" });
});

/**
 * 基础路由
 */
const AdminController = require("@/controllers/admin/admin-controller");
const AdminVaildate = require("@/validates/admin/admin-validate");
const MulterUpload = require("@/utils/upload");
router.get("/admin/captcha", AdminController.captcha); // 图形验证码
router.post(
  "/admin/register",
  AdminVaildate.register,
  AdminController.register
); // 注册
router.get("/admin/login", AdminVaildate.login, AdminController.login); // 登录
router.post(
  "/admin/upload",
  MulterUpload.single("file"),
  AdminController.upload
); // 上传文件
router.get("/admin/user", AdminController.user); // 获取登录用户信息
router.get("/admin/menus", AdminController.menus); // 获取登录用户权限菜单
/**
 * 用户管理
 */
const UserController = require("@/controllers/admin/user-controller");
const UserValidate = require("@/validates/admin/user-validate");
router.post("/users", UserValidate.append, UserController.append);
router.delete("/users/:id", UserController.remove);
router.put("/users/:id", UserValidate.append, UserController.edit);
router.get("/users", UserController.page);
router.get("/users/:id", UserController.detail);
router.patch("/users/:id/status/:status", UserController.status);

/**
 * 角色管理
 */
const RoleController = require("@/controllers/admin/roule-controller");
router.get("/roles/:id", RoleController.detail);
router.get("/roles", RoleController.page);
router.post("/roles", RoleController.append);
router.put("/roles/:id", RoleController.edit);
router.delete("/roles/:id", RoleController.remove);

/**
 * 部门管理
 */
const DeptController = require("@/controllers/admin/dept-controller");
router.get("/depts/:id", DeptController.detail);
router.get("/depts", DeptController.page);
router.post("/depts", DeptController.append);
router.put("/depts/:id", DeptController.edit);
router.delete("/depts/:id", DeptController.remove);

/**
 * 菜单管理
 */
const MenuController = require("@/controllers/admin/menu-controller");
const MenuValidate = require("@/validates/admin/menu-validate");
router.get("/menus", MenuController.page);
router.get("/menus/:id", MenuController.detail);
router.post("/menus", MenuValidate.append, MenuController.append);
router.put("/menus/:id", MenuValidate.append, MenuController.edit);
router.delete("/menus/:id", MenuController.remove);

module.exports = router;
